package com.sponsorpay.sdk.android.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;

public class SignatureTools
{
  public static final String NO_SHA1_RESULT = "nosha1";
  private static final String SHA1_ALGORITHM = "SHA1";

  public static String byteArray2Hex(byte[] paramArrayOfByte)
  {
    Formatter localFormatter = new Formatter();
    int i = paramArrayOfByte.length;
    for (int j = 0; ; j++)
    {
      if (j >= i)
      {
        String str = localFormatter.toString();
        localFormatter.close();
        return str;
      }
      byte b = paramArrayOfByte[j];
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Byte.valueOf(b);
      localFormatter.format("%02x", arrayOfObject);
    }
  }

  public static String generateSHA1ForString(String paramString)
  {
    try
    {
      String str = byteArray2Hex(MessageDigest.getInstance("SHA1").digest(paramString.getBytes()));
      return str;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      SponsorPayLogger.e("UrlBuilder", "SHA1 algorithm not available.");
      localNoSuchAlgorithmException.printStackTrace();
    }
    return "nosha1";
  }

  public static String generateSignatureForParameters(Map<String, String> paramMap, String paramString)
  {
    TreeSet localTreeSet = new TreeSet();
    localTreeSet.addAll(paramMap.keySet());
    Iterator localIterator = localTreeSet.iterator();
    String str2;
    String str3;
    for (String str1 = ""; ; str1 = str1 + String.format("%s=%s&", new Object[] { str2, str3 }))
    {
      if (!localIterator.hasNext())
        return generateSignatureForString(str1, paramString);
      str2 = (String)localIterator.next();
      str3 = (String)paramMap.get(str2);
    }
  }

  public static String generateSignatureForString(String paramString1, String paramString2)
  {
    return generateSHA1ForString(paramString1 + paramString2);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.sponsorpay.sdk.android.utils.SignatureTools
 * JD-Core Version:    0.6.2
 */